package com.easyn.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.easyn.CamLinePro.AllDayRecordActivity;
import com.easyn.CamLinePro.R;

public class RecordSetAdapter extends BaseAdapter {
	private ViewHolder viewHolder;
	private Context mContext;
	private ArrayList<String> list;

	public RecordSetAdapter(Context mContext, ArrayList<String> list) {
		this.mContext = mContext;
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.item_listview_record_set, parent, false);
			viewHolder = new ViewHolder();
			viewHolder.ivDelete = (ImageView) convertView
					.findViewById(R.id.list_delete);
		
			viewHolder.txWeek = (TextView) convertView.findViewById(R.id.week);
			viewHolder.txStart = (TextView) convertView
					.findViewById(R.id.start);
			viewHolder.txStop = (TextView) convertView.findViewById(R.id.stop);

			convertView.setTag(viewHolder);
		} else {

			viewHolder = (ViewHolder) convertView.getTag();
		}
		String info = list.get(position);
		if (AllDayRecordActivity.mIsEdit) {
			viewHolder.ivDelete.setVisibility(View.VISIBLE);
		}else{
			viewHolder.ivDelete.setVisibility(View.GONE);
			viewHolder.ivDelete.setImageResource(R.drawable.delete_befor);
		}
		String oldString = info.substring(0, info.length()-12);
		viewHolder.txWeek.setText(oldString);

		String newString = info.substring(info.length()-12, info.length());
		viewHolder.txStart.setText(newString.split("——")[0]);
		viewHolder.txStop.setText(newString.split("——")[1]);
		return convertView;
	}

	class ViewHolder {
		public ImageView ivDelete;
		public TextView txWeek;
		public TextView txStart;
		public TextView txStop;

	}

}
